<template>
  <div class="app-container" style="margin-top: 10px;">
    <el-card class="box-card" style="height: 765px;" >
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" >
        <el-form-item label="意见类型" prop="productType">
          <el-select
            v-model="queryParams.productType"
            placeholder="请选择意见类型"
            clearable
          >
            <el-option
              v-for="dict in dict.type.yh_product_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>





<!--        <el-form-item label="意见内容" prop="productModel">-->
<!--          <el-input-->
<!--            v-model="queryParams.productModel"-->
<!--            placeholder="请输入意见内容"-->
<!--            clearable-->
<!--            @keyup.enter.native="handleQuery"-->
<!--          />-->
<!--        </el-form-item>-->



        <!--<el-form-item label="昵称" prop="userName">
          <el-input
            v-model="queryParams.userName"
            placeholder="请输入昵称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>-->


<!--        <el-form-item label="所在部门" prop="deptName">-->
<!--          <el-input-->
<!--            v-model="queryParams.deptName"-->
<!--            placeholder="请输入所在部门"-->
<!--            clearable-->
<!--            @keyup.enter.native="handleQuery"-->
<!--          />-->
<!--        </el-form-item>-->

        <br/>
        <div style="text-align: right;">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" >搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button>
          </el-form-item>
        </div>
      </el-form>
      <br/>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"

          >发布</el-button>
        </el-col>
        <!--<el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['module:cjl:budget:edit']"
          >修改</el-button>
        </el-col>-->
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"

          >删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
      </el-row>
        <el-table v-loading="loading" :data="feedback" border @selection-change="handleSelectionChange" style="margin-top: 8px;">
                <el-table-column type="selection" width="55" align="center" />
<!--          <el-table-column label="序号" align="center" prop="id" width="60"/>-->
                <el-table-column type="index" label="序号" width="55"  align="center" />
          <el-table-column label="昵称" align="center" prop="user.userName" v-if="columns[2].visible"/>
<!--          <el-table-column label="用户ID" align="center" prop="userId" v-if="columns[0].visible"/>-->
          <el-table-column label="所在部门" align="center" key="deptName" prop="dept.deptName" v-if="columns[3].visible"/>
<!--          <el-table-column label="现任职务" align="center" prop="base.presentOccupation" v-if="columns[4].visible">-->
<!--            <template slot-scope="scope">-->
<!--              <dict-tag :options="dict.type.yh_present_occupation" :value="scope.row.baseinfo.presentOccupation"/>-->
<!--            </template>-->
<!--          </el-table-column>-->
          <el-table-column label="意见类型" align="center" prop="productType" v-if="columns[0].visible">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.yh_product_type" :value="scope.row.productType"/>
          </template>
          </el-table-column>

          <el-table-column label="意见内容" align="center" prop="productModel" v-if="columns[1].visible"/>


          <el-table-column label="反馈状态" align="center" prop="note2" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="commit(scope.row)"

              >反馈</el-button>
              <el-button
                size="mini"
                type="text"
                @click="commit(scope.row)"

              >处理</el-button>

              <el-button
                size="mini"
                type="text"
                @click="handlelook(scope.row)"
              >详情
              </el-button>
            </template>
          </el-table-column>

        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

      <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
        <el-form ref="form" :model="form" :rules="rules" label-width="130px">
          <el-container>
            <el-header>
              <el-divider content-position="left">
<!--                <p style="color: #00afff; font-size: 20px;">反馈信息</p>-->
              </el-divider>
            </el-header>
            <el-main>
              <el-row>
                <el-col :span="22">
                  <el-form-item label="联系方式" prop="note1">

                    <el-input v-model="up.note1"   type="input"  style="width: 100%"/>
                  </el-form-item>
                </el-col>
              </el-row>

              <el-row>
                <el-col :span="22">
                  <el-form-item label="意见类型" prop="productType">
                    <el-select v-model="form.productType" placeholder="请选择意见类型" style="width:100%;float:left">
                      <el-option
                        v-for="dict in dict.type.yh_product_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      ></el-option>
                    </el-select>
<!--                    <el-input v-model="form.productType" placeholder="请选择意见类型" style="width: 100%"/>-->
                  </el-form-item>
                </el-col>

              </el-row>
              <el-row>
                <el-col :span="22">
                  <el-form-item label="意见内容" prop="productModel">

                    <el-input v-model="form.productModel"  type="textarea" :autosize="{ minRows: 5, maxRows: 8}" placeholder="请输入您的意见内容" style="width: 100%"/>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col span="12">
                  <el-form-item label="图片路径" prop="note3">
                    <image-upload v-model="form.note3"/>
                  </el-form-item>
                </el-col>
              </el-row>

            </el-main>
          </el-container>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>

    </el-card>

  </div>
</template>

<script>

import {getBack, listNumber, addBack, delBack,getName,addcommit} from "@/api/module/zxm/searchNumber";
import { listContract, getContract, delContract, addContract, updateContract } from "@/api/module/cjl/contract";
import { getToken } from "@/utils/auth";
import { treeselect } from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Contract",
  dicts: ['sys_job_status','yh_product_type','yh_contract_type','yh_present_occupation','yh_contract_declare','yh_item_classification','yh_representative_office','yh_equipment_contractor_unit','yh_contractor_unit'],
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 部门树选项
      deptOptions: undefined,
      // 合同台账表格数据
      feedback: [],
      up:{
        note1:"",
      },
      // 岗位选项
      postOptions: [],
      // 部门名称
      deptName: undefined,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        username: null,
        menuId: null,
        menuname: null,
      },
      // 表单参数
      form: {},
      // 用户查询参数
      view:{
        // 是否显示弹出层（用户查询）
        open: false,
        // 弹出层标题（用户查询）
        title: "",
      },
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/module/cjl/contract/importData"
      },
      // 列信息
      columns: [
        {key: 0, label: `序号`, visible: true},
        {key: 1, label: `意见类型`, visible: true},
        {key: 2, label: `意见内容`, visible: true},
        {key: 3, label: `所在部门`, visible: true},
        {key: 4, label: `发布人`, visible: true},

      ],
      // 表单校验
      // rules: {  sequenceNumber: [
      //     { required: true, message: "合同流水号不能为空", trigger: "blur" },
      //   ],
      //   contractType: [
      //     { required: true, message: "合同类别不能为空", trigger: "blur" },
      //   ],
      //   equipVersion: [
      //     { required: true, message: "装备型号不能为空", trigger: "blur" },
      //   ],
      //   contractNo: [
      //     { required: true, message: "合同编号不能为空", trigger: "blur" },
      //   ],
      //   managementAgency: [
      //     { required: true, message: "项目管理机构不能为空", trigger: "blur" },
      //   ],
      //   equipmentContractorUnit: [
      //     { required: true, message: "装备承制单位不能为空", trigger: "blur" },
      //   ],
      //   matchingContractNo: [
      //     { required: true, message: "配套合同/协议号不能为空", trigger: "blur" },
      //   ],
      //   contractorUnit: [
      //     { required: true, message: "承制单位不能为空", trigger: "blur" },
      //   ],
      // }
    };
  },
  created() {
    this.getList();
    this.getTreeselect();
    this.getUser();
  },
  methods: {
    change(e) {
      this.$forceUpdate()
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      getBack(this.queryParams).then(response => {
        this.feedback = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //查询手机号信息
    getUser(){
      getName().then(response => {
        this.up = response.data;
        this.$set(this.up, 'note1', this.up.note1);
        this.loading = false;
      });
    },
  //提交审核
    commit(row) {
      this.reset();
      const id = row.id || this.ids
      addcommit(id).then(response => {
        this.feedback= response.data;
        this.$modal.msgSuccess("提交成功");
        this.getList();
      });
    },

    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮
    viewCancel() {
      this.view.open = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        sequenceNumber: null,
        projectName: null,
        contractType: null,
        equipName: null,
        equipVersion: null,
        quantity: null,
        technicalConditions: null,
        contractNo: null,
        contractDeclare: null,
        representativeOffice: null,
        regulation: null,
        projectType: null,
        purchasingDepartment: null,
        taskConfirmationTime: null,
        executiveStaff: null,
        taskStatus: "0",
        completionTime: null,
        note: null,
        paymentTime: null,
        managementAgency: null,
        equipmentContractorUnit: null,
        scheduleTarget: null,
        contractorUnit: null,
        matchingContractNo: null,
        generalRepresentativeOffice: null,
        generalContractorUnit: null,
        projectManagementAgency: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.is=selection.map(item => item.sequenceNumber)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "意见反馈信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getContract(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改合同台账";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContract(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBack(this.form).then(response => {
              this.$modal.msgSuccess("发布成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 详细按钮操作 */
    handleView(row) {
      const id = row.id || this.ids
      getContract(id).then(response => {
        this.form = response.data;
        this.view.open = true;
        this.view.title = "查看合同台账信息";
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除该条数据？').then(function() {
        return delBack(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('module/cjl/contract/export', {
        ...this.queryParams
      }, `contract_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "合同台账信息导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('module/cjl/contract/importTemplate', {
      }, `contract_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    handlelook(row) {
      const id = row.id;

      const params = {pageNum: this.queryParams.pageNum};
      this.$router.push({path: "/zonghe/fbtoxiangqing", query: {id}});
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
<style>
.el-header, .el-footer {
  background-color: #FFFFFF;
  color: #333;
  text-align: left;
  line-height: 60px;
  font-style: oblique;

}

.el-textarea__inner{
   font-family:"Microsoft";
   font-size:14px;
 }

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  text-align: center;
  line-height: 200px;
}
body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

/*对话框标题样式*/
.el-dialog__title{
  /*color: #1ab394;*/
  font-weight: bold;
  font-size: 25px;
}
</style>
